home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Brushes and Pens / StarGradientBrush / StarGradientBrush.cs next >
Encoding:
Text File  |  2001-01-15  |  1.2 KB  |  38 lines

  1. //------------------------------------------------
  2. // StarGradientBrush.cs ⌐ 2001 by Charles Petzold
  3. //------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8.  
  9. class StarGradientBrush: PrintableForm
  10. {
  11.      public new static void Main()
  12.      {
  13.           Application.Run(new StarGradientBrush());
  14.      }
  15.      public StarGradientBrush()
  16.      {
  17.           Text = "Star Gradient Brush";
  18.      }
  19.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  20.      {
  21.           Point[] apt = new Point[5];
  22.           
  23.           for (int i = 0; i < apt.Length; i++)
  24.           {
  25.                double dAngle = (i * 0.8 - 0.5) * Math.PI;
  26.                apt[i] = new Point(
  27.                          (int)(cx * (0.50 + 0.48 * Math.Cos(dAngle))),
  28.                          (int)(cy * (0.50 + 0.48 * Math.Sin(dAngle))));
  29.           }
  30.           PathGradientBrush pgbrush = new PathGradientBrush(apt);
  31.  
  32.           pgbrush.CenterColor = Color.White;
  33.           pgbrush.SurroundColors = new Color[1] { Color.Black };
  34.  
  35.           grfx.FillRectangle(pgbrush, 0, 0, cx, cy);
  36.     }
  37. }
  38.